﻿using DB.Dapper;
using Orther.Model.param;
using Project.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Entity.DomainModels;

namespace Orther.Service.Miyao
{
    public class UserService
    {
        private string mainSql = "select * from sys_user where 1=1 ";

        public List<Sys_User> GetPageList(UserParam param, Pagination pagination)
        {
            int total = 0;
            FilterClass filterClass = this.WhereFilter(param);
            List<Sys_User> list = DapperUtilsForMysql.PaginationZjc<Sys_User>(mainSql, pagination.PageIndex, pagination.PageSize, ref total, "CreateDate desc", filterClass.where, filterClass.parameters);
            List<Sys_User> newList = new List<Sys_User>();
            list.ForEach(x =>
            {
                x.UserPwd = null;
                newList.Add(x);
            });
            pagination.TotalCount = total;
            return newList;
        }
        public async Task<List<Sys_User>> GetList(UserParam param)
        {
            FilterClass filterClass = this.WhereFilter(param);
            List<Sys_User> list = await DapperUtilsForMysql.queryList<Sys_User>(mainSql, filterClass.parameters, "CreateDate desc", filterClass.where);
            List<Sys_User> newList = new List<Sys_User>();
            list.ForEach(x =>
            {
                x.UserPwd = null;
                newList.Add(x);
            });
            return newList;
        }
        private FilterClass WhereFilter(UserParam param)
        {
            FilterClass filterClass = new FilterClass();

            if (param.User_Id!=null)
            {
                filterClass.where = filterClass.where + " and User_Id=@User_Id ";
                filterClass.parameters.Add("@User_Id", param.User_Id);
            }

            return filterClass;
        }


    }
}
